package com.kclm.pojo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * @Author : lvhx
 * @Date: 2025/11/4 8:57
 * @Description:
 *  bean 生命周期5步骤
 * 1.实例化Bean(调用无参构造)
 * 2.给Bean属性赋值(调用setter方法)
 * 3.初始化Bean (会调用bean的init方法,容器中使用init-method)
 * 4.使用bean
 * 5.销毁Bean(会调用bean的destroy方法，容器中使用destroy-method)
 */
public class User  implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean,DisposableBean{
    private String name;

    public void setName(String name) {
        System.out.println("2.Bean属性赋值");
        this.name = name;
    }

    public User() {
        System.out.println("1.实例化Bean");
    }
    public  void init(){
        System.out.println("6.初始化Bean");
    }
    public void  destroyBean(){
        System.out.println("10.销毁Bean");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("3.bean的name:"+ name);
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("3.bean的classLoader:"+ classLoader);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("3.bean的beanFactory:"+ beanFactory);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("5 afterPropertiesSet被调用");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("9.DisposableBean 中 destroy被调用");
    }
}
